create database QLRapChieuPhimTVB
go
use QLRapChieuPhimTVB
go
-- Tao bang Phim
create table Phim
(	MaPhim int primary key,
	TenPhim nvarchar(200),
	MaLoaiPhim int,
	MaPhienBan int,
	MaQuocGia int,
	DoDai int,
	NgayBatDau smalldatetime,
	NgayKetThuc smalldatetime,
	HinhAnh varchar(100),
	MoTaPhim nvarchar(500),
)
go
create table LoaiPhim
(
	MaLoaiPhim int primary key,
	TenLoaiPhim nvarchar(100)
)
go
create table PhienBanPhim
(
	MaPhienBan int primary key,
	TenPhienBan varchar(10)
)
go
create table QuocGia
(
	MaQuocGia int primary key,
	TenQuocGia nvarchar(20)
)
go
create table SuatChieu
(
	MaSuatChieu int primary key,
	MaPhim int,
	GioChieu smallint,
	PhutChieu smallint 
)
go
create table Ve
(
	MaVe int primary key,
	MaSuatChieu int,
	MaRap int,
	GiaVe money,
	MaKhuyenMai int,
	MaLichChieu int,
	MaPhim int,
	MaGhe int,
)
go
create table KhuyenMai
(
	MaKhuyenMai int primary key,
	TenChuongTrinhKM nvarchar(20),
	NgayBatDauKM smalldatetime,
	NgayKetThucKM smalldatetime,
	NoiDungKM nvarchar(50),
	HinhAnhKM varchar(100),
)
go
create table LichChieu
(
	MaLichChieu int primary key,
	MaSuatChieu int,
	MaRap int,
	NgayChieu smalldatetime
)
go
create table Rap
(
	MaRap int primary key,
	TenRap nvarchar(30),
	TrangThai nvarchar(20),
	SoLuongGhe int,
	GhiChuRap nvarchar(100)
)
go
create table Ghe
(
	MaGhe int,
	MaRap int,
	LoaiGhe nvarchar(10),
	primary key(MaGhe,MaRap)
)
--Tao cac khoa ngoai
alter table Phim
	add constraint FK_Phim_LoaiPhim foreign key(MaLoaiPhim) references LoaiPhim(MaLoaiPhim)
alter table Phim
	add constraint FK_Phim_PhienBanPhim foreign key(MaPhienBan) references PhienBanPhim(MaPhienBan)
alter table Phim
	add constraint FK_Phim_QuocGia foreign key(MaQuocGia) references QuocGia(MaQuocGia)
go
alter table SuatChieu
	add constraint FK_SuatChieu_Phim foreign key(MaPhim) references Phim(MaPhim)
go
alter table LichChieu
	add constraint FK_LichChieu_SuatChieu foreign key(MaSuatChieu) references SuatChieu(MaSuatChieu)
alter table LichChieu
	add constraint FK_LichChieu_Rap foreign key(MaRap) references Rap(MaRap)
alter table Ve
	add constraint FK_Ve_SuatChieu foreign key(MaSuatChieu) references SuatChieu(MaSuatChieu)
alter table Ve
	add constraint FK_Ve_KhuyenMai foreign key(MaKhuyenMai) references KhuyenMai(MaKhuyenMai)
alter table Ve
	add constraint FK_Ve_Rap foreign key(MaRap) references Rap(MaRap)
go
alter table Ghe
	add constraint FK_Ghe_Rap foreign key(MaRap) references Rap(MaRap)